#include "serviceview_console_impl.h"
#include "employee.h"
#include "department.h"

using namespace std;

ServiceViewConsoleImpl::ServiceViewConsoleImpl(void)
{
	service = new ServiceImpl;
}

void ServiceViewConsoleImpl::menu(void)
{
	
	while(1)
	{
		system("clear");
		cout<<"*****企业管理系统*****"<<endl;
		cout<<"1、增加部门"<<endl;
		cout<<"2、删除部门"<<endl;
		cout<<"3、列出所有部门"<<endl;
		cout<<"4、增加员工"<<endl;
		cout<<"5、删除员工"<<endl;
		cout<<"6、修改员工信息"<<endl;
		cout<<"7、列出部门员工"<<endl;
		cout<<"8、列出所有部门员工"<<endl;
		cout<<"9、列表显示"<<endl;
		cout<<"0、返回上一级"<<endl;
		cout<<"------------------"<<endl;
		cout<<"请选择您的业务选项:";

		int choose;
		cin>>choose;
		switch(choose)
		{
			case ADDDEPT:addDept();break;
			case DELDEPT:deleteDept();break;
			case LISTDEPT:listDept();break;
			case ADDEMP:addEmp();break;
			case DELEMP:deleteEmp();break;
			case MODIFYEMP:modifyEmp();break;
			case LISTEMP:listEmp();break;
			case LISTALLEMP:listAllEmp();break;
			case MYLIST:my_list();break;
			case FRONT:return;
		}
	}
}

void ServiceViewConsoleImpl::addDept(void)
{
	int m_id = generator_DeptId();

	char temp_name[20];
	cout<<"请输入添加部门名称:";
	cin>>temp_name;
	Department department(m_id,temp_name);
	if(service->addDept(department))
	{
		cout << "添加部门成功" << endl;
	}
	else
	{
		cout << "添加部门失败" << endl;
	}
	anykey_continue();

}
void ServiceViewConsoleImpl::deleteDept(void)
{
	int id = 0;
	cout << "请输入删除部门id:";
	cin >> id;
	if(service->deleteDept(id))
	{
		cout << "删除部门成功!" << endl;
	}
	else
	{
		cout << "该部门不存在，删除部门失败!" << endl;
	}
	anykey_continue();
}
void ServiceViewConsoleImpl::listDept(void)
{
	service->listDept();
	anykey_continue();
}
void ServiceViewConsoleImpl::addEmp(void)
{
	int m_id = generator_EmpId();
	
	char temp_name[20];
	bool sex;
	int temp_age;
	int dept_id;

	cout<<"请输入添加员工的姓名:";
	cin>>temp_name;
	cout<<"请输入员工的性别(男1/女0):";
	cin>>sex;
	cout<<"请输入员工的年龄:";
	cin>>temp_age;
	cout<<"请输入加入部门id:";
	cin>>dept_id;

	Employee employee(temp_name,sex,temp_age,m_id);
	if(service->addEmp(employee,dept_id))
	{
		cout << "添加员工成功!" << endl;
	}
	else
	{
		cout << "该部门不存在,添加员工失败!" << endl;
	}
	anykey_continue();
}
void ServiceViewConsoleImpl::deleteEmp(void)
{
	int m_id = 0;
	cout<<"请输入要删除员工的id:";
	cin>>m_id;
	if(service->deleteEmp(m_id))
	{
		cout<<"删除员工成功!" << endl;
	}
	else
	{
		cout << "该用户不存在,删除失败" << endl;
	}
	anykey_continue();
}
void ServiceViewConsoleImpl::modifyEmp(void)
{

	char temp_name[20];
	bool sex;
	int temp_age;
	int m_id;
	
	cout<<"请输入员工id:";
	cin>>m_id;
	cout<<"请输入员工的姓名:";
	cin>>temp_name;
	cout<<"请输入员工的性别(男1/女0):";
	cin>>sex;
	cout<<"请输入员工的年龄:";
	cin>>temp_age;

	Employee employee(temp_name,sex,temp_age,m_id);
	if(service->modifyEmp(employee))
	{
		cout << "修改员工信息成功" << endl;
	}
	else
	{
		cout << "该员工不存在,修改员工信息失败" << endl;
	}
	anykey_continue();
}
void ServiceViewConsoleImpl::listEmp(void)
{
	
	int m_id = 0;
	cout<<"请输入要列出部门的id:";
	cin>>m_id;
	service->listEmp(m_id);

	anykey_continue();
}
void ServiceViewConsoleImpl::listAllEmp(void)
{
	service->listAllEmp();
	anykey_continue();
}

void ServiceViewConsoleImpl::my_list(void)
{
	service->myList();
	anykey_continue();

}

ServiceViewConsoleImpl::~ServiceViewConsoleImpl(void)
{
	delete []service;
}
